<!DOCTYPE html>
<html height100 xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta th:replace="authority/common/currency/head"/>
</head>

<body class="childrenBody" padding10>

<div id="seach-container"></div>
<table id="dml-table" lay-filter="dml-table" class="layui-hide zsa-auto-height"></table>

<script type="text/html" id="sys_toolbarDemo">
    <button class="layui-btn layui-btn-sm" lay-event="sys_toolbar_search">搜索</button>
    <button class="layui-btn layui-btn-sm" lay-event="sys_toolbar_refresh">
        <i class="layui-icon" style="line-height:30px">&#xe669;</i>
    </button>
    <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="sys_toolbar_add">
        <i class="layui-icon" style="line-height:30px">&#xe654;</i>添加
    </button>
</script>
<!--操作-->
<script type="text/html" id="toolDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe642;</i>编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
</script>

<script th:replace="authority/common/currency/footer"></script>
<script>
    layui.extend({
        complexSearch: 'complexSearch/complexSearch', // {/}的意思即代表采用自有路径，即不跟随 base 路径
        initTable: 'initTable/initTable'
    });
    layui.use(['initTable', 'complexSearch', 'lutil'], function () {
        var table = layui.table
            , complexSearch = layui.complexSearch
            , layer = layui.layer
            , lutil = layui.lutil;
        // 搜索框
        var search = complexSearch.render({
            container: "#seach-container",
            isDynamic: false,
            submit: false,
            returnFormat: {
                dataTypeName: 'type'
            },
            data: [
                // {field: 'id', title: 'ID', editType: 'text', dataType: 'string', formulas: ['<->']},
                {field: 'name', title: '名称', editType: 'text', dataType: 'string', formulas: ['<->']},
                {
                    field: 'modifyTime',
                    title: '最后修改时间',
                    editType: 'date',
                    dateType: 'datetime',
                    dataType: 'date',
                    formulas: ['range', '=', '>', '<'],
                    formula: 'range'
                }, {
                    field: 'isValid',
                    formulas: ['='],
                    dataType: 'int',
                    title: '是否有效',
                    editType: 'select',
                    options: [{key: '请选择', value: ''}, {key: '是', value: '1'}, {key: '否', value: '0'}]
                }
            ],
            search: function (data) {
                var thisTable = layui.pageObtainTable('dml-table');
                thisTable && thisTable.query({searchs: data.length > 0 ? JSON.stringify(data) : ''});
            }
        });

        var height = $(window).height() - $('#seach-container').outerHeight() - 40,
            height_value = parseInt(height) > 300 ? parseInt(height) : 300;

        layui.page_table_examples.push(table.render({
            elem: '#dml-table',
            url: content_path + 'authority/timed_task_cron/list.do',
            height: height_value,
            toolbar: '#sys_toolbarDemo',
            title: 'dml列表',
            cellMinWidth: '100',
            headers: {'[[${_csrf.headerName}]]': '[[${_csrf.token}]]'},
            cols: [
                [//标题栏
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'id', title: 'ID', fixed: 'left', width: 100},
                    {field: 'name', title: '名称', sort: true, fixed: 'left', width: 150},
                    {field: 'cron', title: 'CRON语句', fixed: 'left', width: 160},
                    {field: 'remark', title: '备注', minWidth: 200},
                    {field: 'modifyTime', title: '最后修改时间', sort: true, width: 160},
                    {field: 'modifyUserName', title: '最后修改人', width: 110},
                    {
                        field: 'state', title: '是否有效', sort: true, fixed: 'right', align: 'center', width: 100,
                        templet: function (d) {
                            return '<span' + (d.state === 1 ? ' style="color:green;" >正常' : 'style="color:#eee;" >无效') + '</span>';
                        }
                    },
                    {field: 'cz', title: '操作', width: 160, toolbar: "#toolDemo", fixed: 'right', align: 'center'}
                ]
            ]
        }));

        //头工具栏事件
        table.on('toolbar(dml-table)', function (obj) {
            var thisTable = layui.pageObtainTable('dml-table');
            var checks = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'sys_toolbar_refresh':
                    thisTable && thisTable.refresh();
                    break;
                case  'sys_toolbar_search':
                    search.submit();
                    break;
                case 'sys_toolbar_add':
                    lutil.open_iframe("新增DML", content_path + "authority/timed_task_cron/edit.html", null, null, function () {
                        thisTable && thisTable.refresh();
                    });
                    break;
            }
        });

        table.on('sort(dml-table)', function (obj) {
            var thisTable = layui.pageObtainTable('dml-table');
            thisTable && thisTable.sort(obj);
        });

        table.on('tool(dml-table)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var thisTable = layui.pageObtainTable('dml-table');
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (layEvent === 'edit') {
                lutil.open_iframe("编辑 - " + data['name'], content_path + "authority/timed_task_cron/edit.html?id=" + data['id'], null, null, function () {
                    thisTable && thisTable.refresh();
                });
            }
            if (layEvent === 'del') {
                lutil.my_confirm("确定要删除CRON“" + data['name'] + "” ，将不可恢复？？", function () {
                    var loding = layer.load(2, {shade: [0.3, '#eee']});
                    ajaxRequestByCsrf(content_path + "authority/timed_task_cron/del.do", {id: data['id']}, function (res) {
                        lutil.success_msg(res.message);
                        thisTable && thisTable.refresh();
                    }, null, function () {
                        layer.close(loding);
                    })
                })
            }
        });

    })
</script>
</body>
</html>